﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Configuration;


namespace Microsoft.Mtool.FSM
{
    [Serializable]
    public class FunctionImpl : ActionImpl
    {
        private Action action;

        [XmlElement]
        public Action InnerAction
        {
            get { return action; }
            set { action = value; }
        }

        internal override void GenDefaults()
        {
            if (action == null || action.Stubs == null) return;
            inParas = new List<Parameter>();
            outParas = new List<Parameter>();
            foreach (ActionImpl impl in action.Stubs)
            {
                foreach (Parameter p in impl.InParas)
                    if (p.Var.IsVar && InParasText.IndexOf(p.Var.Name) == -1 && OutParasText.IndexOf(p.Var.Name) == -1)
                    {
                        Parameter cp = p.GetCopyWithoutVarValues();
                        cp.Name = p.Var.Name;
                        inParas.Add(cp);
                    }
                foreach (Parameter p in impl.OutParas)
                    if (p.Var.IsVar && OutParasText.IndexOf(p.Var.Name) == -1)
                    {
                        Parameter cp = p.GetCopyWithoutVarValues();
                        cp.Name = p.Var.Name;
                        outParas.Add(cp);
                    }
            }
        }

        override public ActionImpl GetCopy()
        {
            FunctionImpl newImpl = new FunctionImpl();
            newImpl.Name = this.Name;
            newImpl.InnerAction = this.InnerAction;
            newImpl.GenDefaults();
            return newImpl;
        }

        public override string ToString()
        {
            return string.Format("[Function]{0}", Name);
        }
    }
}
